#include "searcher.hpp"
#include"cpp-httplib/httplib.h"

const std::string input="data/raw_html/raw.txt";
const std::string root_path="./wwwroot";

int main()
{
    ns_searcher::Searcher search;
    search.InitSearcher(input);

    //for test
    httplib::Server svr;
    svr.set_base_dir(root_path);
    svr.Get("/s",[&search](const httplib::Request&req,httplib::Response& rsp ){
        if(!req.has_param("word"))//用户没有输入关键字
        {
            rsp.set_content("必须要有搜索关键字！！！","text/plain; charset=utf-8");
            return;
        }
        std::string word=req.get_param_value("word");//得到用户输入的关键字
        std::cout<<"用户在搜索："<<word<<std::endl;

        std::string json_string;
        search.Search(word,json_string);
        rsp.set_content(json_string,"application/json");
        //rsp.set_content("hello word!","text/plain");
    });
    svr.listen("0.0.0.0",8080);
    return 0;
}